package top.jiangqiang.qyblog.admin.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import top.jiangqiang.qyblog.common.base.controller.BaseController;
import top.jiangqiang.qyblog.common.base.query.PageResult;
import top.jiangqiang.qyblog.common.base.response.Result;
import top.jiangqiang.qyblog.common.constant.RequestURLConstants;
import top.jiangqiang.qyblog.core.domain.dto.BlogTagAddDto;
import top.jiangqiang.qyblog.core.domain.dto.BlogTagUpdateDto;
import top.jiangqiang.qyblog.core.domain.dto.TagQueryDto;
import top.jiangqiang.qyblog.core.domain.vo.BlogTagVo;
import top.jiangqiang.qyblog.core.service.ITagService;

/**
 * @author jiangqiang
 * @date 2022-11-27
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(RequestURLConstants.TAG_CONTROLLER_PREFIX)
@Tag(name = "博客标签接口")
public class TagController extends BaseController {
    private final ITagService tagService;

    @GetMapping
    @Operation(summary = "根据条件查询标签列表", description = "查询标签列表")
    public Result<PageResult<BlogTagVo>> list(@ParameterObject TagQueryDto tagQueryDto) {
        return tagService.findByCondition(tagQueryDto);
    }

    @GetMapping("/{id}")
    @Operation(summary = "查询标签详情", description = "根据id查询标签")
    public Result<BlogTagVo> get(@PathVariable Long id) {
        return tagService.getTag(id);
    }

    @PostMapping
    @Operation(summary = "新增标签", description = "新增标签")
    public Result<BlogTagVo> save(@RequestBody BlogTagAddDto tagAddDto) {
        return tagService.saveTag(tagAddDto);
    }

    @PutMapping
    @Operation(summary = "编辑标签", description = "根据id修改标签")
    public Result<BlogTagVo> update(@RequestBody BlogTagUpdateDto tagUpdateDto) {
        return tagService.editTag(tagUpdateDto);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除标签", description = "根据id删除标签")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(tagService.deleteTag(id));
    }

}
